import { chooseFile, chooseDir } from '@/api/flow'
import { ref, Ref } from 'vue'

interface FileSystem {
  open: (fieldtype: string) => Promise<Ref<string>>
}

const useFileSystem = (): FileSystem => {
  const open = async (fieldtype: string) => {
    const result = ref()

    if (fieldtype == 'directory') {
      result.value = await chooseDir()
    } else {
      result.value = await chooseFile()
    }

    return result
  }

  return {
    open
  }
}

export default useFileSystem
